import { BasicColumn, FormSchema } from '/@/components/Table';
import { render } from '/@/utils/common/renderUtils';
import { useI18n } from '/@/hooks/web/useI18n';
const { t } = useI18n('message.mynews');
const { t: fields } = useI18n('message.mynews.fields');
const { t: common } = useI18n('common');

export const mynewsFields = {
  titile: fields('titile'),
  msgCategory: fields('msgCategory'),
  sender: fields('sender'),
  sendTime: fields('sendTime'),
  priority: fields('priority'),
  readFlag: fields('readFlag'),
};
export const columns: BasicColumn[] = [
  {
    title: mynewsFields.titile,
    dataIndex: 'titile',
    width: 100,
    align: 'left',
  },
  {
    title: mynewsFields.msgCategory,
    dataIndex: 'msgCategory',
    width: 80,
    customRender: ({ text }) => {
      return render.renderDictNative(
        text,
        [
          { label: t('msgCategory1'), value: '1', color: 'blue' },
          { label: t('msgCategory2'), value: '2' },
        ],
        true
      );
    },
  },
  {
    title: mynewsFields.sender,
    dataIndex: 'sender',
    width: 80,
  },
  {
    title: mynewsFields.sendTime,
    dataIndex: 'sendTime',
    width: 80,
  },
  {
    title: mynewsFields.priority,
    dataIndex: 'priority',
    width: 80,
    customRender: ({ text }) => {
      const color = text == 'L' ? 'blue' : text == 'M' ? 'yellow' : 'red';
      return render.renderTag(render.renderDict(text, 'priority'), color);
    },
  },
  {
    title: mynewsFields.readFlag,
    dataIndex: 'readFlag',
    width: 80,
    customRender: ({ text }) => {
      return render.renderDictNative(
        text,
        [
          { label: common('read'), value: '0', color: 'red' },
          { label: common('unread'), value: '1' },
        ],
        true
      );
    },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'titile',
    label: mynewsFields.titile,
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'sender',
    label: mynewsFields.sender,
    component: 'Input',
    colProps: { span: 8 },
  },
];
